//
//  ChildViewController.m
//  LoveDraw
//
//  Created by 梁晨 on 2017/6/13.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "ChildViewController.h"
#import "ChildViewTableViewCell.h"
#import "ChildModel.h"

//二级界面
#import "ChildDetailViewController.h"

@interface ChildViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *ListTabV;
@property(nonatomic,strong)NSMutableArray *listArr;

@end

@implementation ChildViewController


/**
 表试图

 @return 列表视图
 */
-(UITableView *)ListTabV
{
    if (!_ListTabV) {
        _ListTabV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KscreenW, KscreenH-64) style:(UITableViewStyleGrouped)];
        _ListTabV.delegate = self;
        _ListTabV.dataSource = self;
        _ListTabV.separatorStyle = 0;
        _ListTabV.estimatedSectionHeaderHeight = 0;
        _ListTabV.estimatedSectionFooterHeight = 0;
        _ListTabV.backgroundColor = [UIColor whiteColor];
        [_ListTabV registerNib:[UINib nibWithNibName:@"ChildViewTableViewCell" bundle:nil] forCellReuseIdentifier:@"ChildViewTableViewCell"];
    }
    return _ListTabV;
}

/**
 数据

 @return 列表数据
 */
-(NSMutableArray *)listArr
{
    if (!_listArr) {
        _listArr = [NSMutableArray array];
    }
    return _listArr;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationItem.title = @"我娃管理";
     [self Request];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.ListTabV];

}


#pragma mark ---- tableV的代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.listArr.count == 0) {
        self.ListTabV.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nodata"]];
    }else
    {
        self.ListTabV.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    }
    return self.listArr.count;
}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return FLT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return FLT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 95;
}
// 111AEF  19222B  CBC5C5 13407580747
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChildModel *model = self.listArr[indexPath.row];
    ChildViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChildViewTableViewCell" forIndexPath:indexPath];
    [cell.TitleimageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KUrl,model.lifethumb]] placeholderImage:Kplaceholderimage];
    cell.NameL.text = model.name;
    cell.numberOfqingjia.text = model.leave_num;
    if ([model.sex isEqualToString:@"男"])
    {
        cell.SexiamgeV.image = [UIImage imageNamed:@"man"];
    }else
    {
        cell.SexiamgeV.image = [UIImage imageNamed:@"women"];
    }

    cell.Class.text = [NSString stringWithFormat:@"就读于“%@”",model.course_name];
    cell.NumberofLessonL.text = [NSString stringWithFormat:@"剩余课次%@",model.classhour_last];
    cell.selectionStyle = 0;
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChildModel *model = self.listArr[indexPath.row];
    ChildDetailViewController *VC = [[ChildDetailViewController alloc]init];
    VC.sid = model.sid;
    VC.className = model.course_name;
    [self.navigationController pushViewController:VC animated:YES];
}



-(void)Request
{
    [RequestManager RequstWithUrl:@"/index.php?g=App&m=StudentInfo&a=index" parmDic:@{} requestType:RequestGET Success:^(id data)
    {
        self.listArr = [ChildModel modelConfigure:data];
        [self.ListTabV reloadData];
    } error:^(NSError *error) {

    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
